package demo02;

import java.util.ArrayList;
import java.util.Random;

//定义方法，生成6个1-33之间的随机数，添加到集合中
//要求不重复，并遍历集合
public class HomeWork05 {
    public static void main(String[] args) {
        ArrayList<Integer> numbers = getRandomNumbers();
        System.out.println("生成的随机数集合：");
        for (int number : numbers) {
            System.out.print(number+" ");
        }
    }

    public static ArrayList<Integer> getRandomNumbers() {
        ArrayList<Integer> numbers = new ArrayList<>();
        Random random = new Random();

        while (numbers.size() < 6) {
            int randomNumber = random.nextInt(33) + 1;
            if (!numbers.contains(randomNumber)) {
                numbers.add(randomNumber);
            }
        }
        return numbers;
    }
}